package controllers

import javax.inject.Inject
import play.api.mvc._
import tool._
import dao._
import org.joda.time.DateTime
import play.api.libs.json.Json
import utils.Utils

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import models.Tables._


/**
  * Created by yz on 2018/8/20
  */
class UserController @Inject()(cc: ControllerComponents, formTool: FormTool,
                               tool: Tool,pdfInfoDao: PdfInfoDao) extends AbstractController(cc) {

  def toHome = Action { implicit request =>
    Ok(views.html.user.home())
  }

  def detailInfoBefore = Action { implicit request =>
      Ok(views.html.user.detailInfo())

  }

  def getPdfInfo = Action.async { implicit request =>
    pdfInfoDao.selectById(0).map { x =>
      val json = Utils.getJsonByT(x)
      Ok(json)
    }

  }

  def updatePdfInfo = Action.async { implicit request =>
    val data = formTool.pdfInfoForm.bindFromRequest().get
    val pdfInfo = PdfInfoRow(0, data.title, data.unit, data.address, data.reporter, data.checker)
    pdfInfoDao.update(pdfInfo).map { x =>
      Ok(Json.toJson("success!"))
    }

  }



}
